#!/bin/bash
PROCESS="java"
MEM_LIMIT=500000 # 500MB
PID=$(pgrep $PROCESS)
[ -z "$PID" ] && exit 0
MEM=$(ps -p $PID -o rss=)
[ $MEM -gt $MEM_LIMIT ] && kill -USR1 $PID && echo "$(date) $PROCESS 内存超标: $((MEM/1024))MB" >> /var/log/mem_alert.log